#导包
from common.readData import ReadData
import unittest
import requests

#1.获取测试数据
#实例化
data_obj = ReadData()
#调用实例方法
test_data = data_obj.read_excel()
#print(test_data)
#定义一个测试类
class TestCase(unittest.TestCase):
    #2.1创建测试用例方法
    def test_case(self):
        #2.2获取测试数据内精选请求需要的关键字段
        url = test_data[0]["interfaceUrl"]
        method =test_data[0]["method"]
        value =eval(test_data[0]["value"])
        header =eval(test_data[0]["header"])
        expect = int(test_data[0]["expect"])
        print(url,method,value,header,expect)
        #2.3进行请求获得返回结果
        if method.lower() == "get":
            re = requests.get(url=url,params=value,headers=header)
        elif method.lower() == "post":
            re = requests.post(url=url,data=value,headers=header)
        res_dict = re.json()
        print(res_dict)
        #2.4断言接口返回结果,判断成功/失败
        self.assertEqual(res_dict["errorCode"],expect,"测试用例不通过")



if __name__ == "__main__":
    unittest.main(verbosity=2)












